﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：庄金冬 
    //
    // 文件名：BLL_ProcurementBasic.cs
    // 文件功能描述： 采购准备操作业务逻辑类,实现接口IBLL_ProcurementBasic,继承自类MarshalByRefObject
    // 创建标识：庄金冬2009-03-06
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/

using System;
using System.Collections.Generic;

using System.Text;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.DAL;
using System.Data;
using System.Diagnostics;

namespace HZ.DrugTrade.BLL
{

    [Serializable]
    /// <summary>
    /// 采购准备操作业务逻辑类,实现接口IBLL_ProcurementBasic,继承自类MarshalByRefObject
    /// </summary>
    public class BLL_ProcurementBasic : MarshalByRefObject, IBLL_ProcurementBasic
    {

        #region IBLL_ProcurementBasic Members

        #region 采购项目
        /// <summary>
        /// 获取所有采购项目
        /// </summary>
        /// <returns>所有采购项目信息</returns>
        /// <remarks>
        /// 获取所有采购项目
        /// </remarks>
        public IList<ProcurementProject> GetAllProcurementProject()
        {
            BLL_UserSession.CheckSession();
            // return DAL.DAL_ProcurementProject.GetAllProcurementProject();
            int temp;
            return GetProjectByWhere(new ProcurementProject() { ProcureStartTimeTo = DateTime.Now, ProcureEndTimeFrom = DateTime.Now }, 1, 0, out temp);

        }

        /// <summary>
        /// 采购项目条件查询（有效的【在采购项目有效期内】）
        /// </summary>
        /// <param name="project">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns></returns>
        public IList<ProcurementProject> GetProjectByWhere(ProcurementProject project, int currentPage, int pageSize, out int totalRecord)
        {
            BLL_UserSession.CheckSession();
            project.ProcureStartTimeTo = project.ProcureStartTimeTo ?? DateTime.Now;
            project.ProcureEndTimeFrom = project.ProcureEndTimeFrom ?? DateTime.Now;
            return DAL_ProcurementProject.GetProjectByWhere(project, currentPage, pageSize, out totalRecord);
        }

        /// <summary>
        /// 采购项目条件查询（无效的【不在采购项目有效期内】）
        /// </summary>
        /// <param name="project">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns></returns>
        public IList<ProcurementProject> GetInvalidProjectByWhere(ProcurementProject project, int currentPage, int pageSize, out int totalRecord)
        {
            BLL_UserSession.CheckSession();
            return DAL_ProcurementProject.GetInvalidProjectByWhere(project, currentPage, pageSize, out totalRecord);
        }


        /// <summary>
        /// 添加采购项目信息（0失败;1成功）
        /// </summary>
        /// <param name="project">采购项目</param>
        /// <returns>0失败;1成功</returns>
        /// <remarks>
        /// ID可以为空，其余字段一律不得为空
        /// 
        /// </remarks>
        public int AddProcurementProject(ProcurementProject project)
        {
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_ProcurementProject.AddProcurementProject(project);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加采购项目信息：{0};处理时间:{1};)", project.ProjectName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 更新采购项目信息（0失败;1成功）
        /// </summary>
        /// <param name="project">采购项目</param>
        /// <returns>0失败;1成功</returns>
        public int UpdateProcurementProject(ProcurementProject project)
        {
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_ProcurementProject.UpdateProcurementProject(project);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购项目信息：{0};处理时间:{1};)", project.ProjectName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 获取采购项目信息
        /// </summary>
        /// <param name="projectID">项目编号</param>
        /// <returns></returns>
        public ProcurementProject GetProcurementProjectByID(string projectID)
        {
            return DAL.DAL_ProcurementProject.GetProcurementProjectByID(projectID);
        }

        /// <summary>
        /// 删除采购项目（0失败;1成功）
        /// </summary>
        /// <param name="projectID">项目编号</param>
        /// <returns>0失败;1成功</returns>
        public int DeleteProcurementProjectByID(string projectID)
        {
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_ProcurementProject.DeleteProcurementProjectByID(projectID);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除采购项目：{0};处理时间:{1};)", projectID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        #endregion

        #region 采购目录

        /// <summary>
        /// 获取所有采购目录
        /// </summary>
        /// <returns></returns>
        public IList<Model.View.ProcureCatalog> GetAllProcureCatalog()
        {
            BLL_UserSession.CheckSession();
            int totalrecord = 0;
            return GetProcureCatalogByWhere(null, 1, 0, out totalrecord);
        }


        /// <summary>
        /// 条件查询采购目录信息（有效的【在采购项目有效期内】）
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public IList<HZ.DrugTrade.Model.View.ProcureCatalog> GetProcureCatalogByWhere(HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            procureCatalog.ProcureStartTimeTo = DateTime.Now;
            procureCatalog.ProcureEndTimeFrom = DateTime.Now;
            return DAL.DAL_ProcureCatalog.GetProcureCatalogByWhere(procureCatalog, currentpage, pagesize, out totalrecord);
        }
        public DataTable GetProcureCatalogByWhere1(HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            procureCatalog.ProcureStartTimeTo = DateTime.Now;
            procureCatalog.ProcureEndTimeFrom = DateTime.Now;
            return DAL.DAL_ProcureCatalog.GetProcureCatalogByWhere1(procureCatalog, currentpage, pagesize, out totalrecord);
        }
        /// <summary>
        /// 条件查询采购目录信息（有效的【在采购项目有效期内】）--带区域条件
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public IList<HZ.DrugTrade.Model.View.ProcureCatalog> GetProcureCatalogByWhereArea(string strAreaID, HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            procureCatalog.ProcureStartTimeTo = DateTime.Now;
            procureCatalog.ProcureEndTimeFrom = DateTime.Now;
            return DAL.DAL_ProcureCatalog.GetProcureCatalogByWhereArea(strAreaID, procureCatalog, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 根据登陆ID查询价格修改权限
        /// </summary>
        /// <param name="strUserID"></param>
        /// <returns></returns>
        public DataTable GetTB_ManageOrg(string strUserID)
        {
            return DAL.DAL_ProcureCatalog.GetTB_ManageOrg(strUserID);
        }

        /// <summary>
        /// 条件查询采购目录信息（有效的【在采购项目有效期内】）
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public DataTable GetProcureCatalogDTByWhere(HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            procureCatalog.ProcureStartTimeTo = DateTime.Now;
            procureCatalog.ProcureEndTimeFrom = DateTime.Now;
            return DAL.DAL_ProcureCatalog.GetProcureCatalogDTByWhere(procureCatalog, currentpage, pagesize, out totalrecord);
        }
        /// <summary>
        /// 条件查询采购目录信息（有效的【在采购项目有效期内】）
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public DataTable GetProcureCatalogDTByWhere2(HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            procureCatalog.ProcureStartTimeTo = DateTime.Now;
            procureCatalog.ProcureEndTimeFrom = DateTime.Now;
            return DAL.DAL_ProcureCatalog.GetProcureCatalogDTByWhere(procureCatalog, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 条件查询采购目录信息（无效的【不在采购项目有效期内】）
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public IList<HZ.DrugTrade.Model.View.ProcureCatalog> GetInvalidProcureCatalogByWhere(HZ.DrugTrade.Model.Query.ProcureCatalog procureCatalog, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_ProcureCatalog.GetInvalidProcureCatalogByWhere(procureCatalog, currentpage, pagesize, out totalrecord);
        }


        /// <summary>
        /// 插入采购目录
        /// </summary>
        /// <param name="procureCatalog">采购目录【采购目录编号ProcureCatalogID，商品编号GoodsID，中标价格ProcurePrice，采购项目编号ProjectID，为必填】</param>
        /// <returns></returns>
        public int AddProcureCatalog(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();

            //生成最大编号
            string sql = "SELECT MAX(ProcureCatalogID) FROM TB_ProcureCatalog  where length(ProcureCatalogID)=8";
            object objProcureCatalogID = HZ.Data.DbHelperFactory.Create().ExecuteScalar(sql);
            if (objProcureCatalogID != null && objProcureCatalogID.ToString().Length == 8)
            {
                procureCatalog.ProcureCatalogID = (int.Parse(objProcureCatalogID.ToString()) + 1).ToString("D8");
            }
            else
            {
                procureCatalog.ProcureCatalogID = "10000001";
            }
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            // TIPS:remarked by lig 20090730
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyIDs_PS), "配送企业编号集合CompanyIDs_PS不能空");
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyNames_PS), "配送企业名称集合CompanyNames_PS不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "ProcureCatalogID不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.GoodsID), "商品编号GoodsID不能空");
            HZ.Common.ThrowHelper.Throw(procureCatalog.ProcurePrice != null, "中标价格ProcurePrice不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProjectID), "采购项目编号ProjectID不能空");
            int totalrecord = 0;
            HZ.DrugTrade.Model.Query.ProcureCatalog pc = new HZ.DrugTrade.Model.Query.ProcureCatalog()
            {
                //商品编号
                GoodsID = procureCatalog.GoodsID,
                //采购项目编号
                ProjectID = procureCatalog.ProjectID
            };
            GetProcureCatalogByWhere(pc, 1, 0, out  totalrecord);
            if (totalrecord != 0)
            {
                //2该商品在项目中已经存在（商品在同一项目中只能存在一个采购目录）
                return 2;
            }
            //添加产品也添加产品到 TB_AreaProcureCataLog  盟市 修改价格列表ProcureCatalogID, ProjectID, GoodsID, AreaID, Price
            //string sqlstr = @" if not exists(select top 1 * from TB_AreaProcureCataLog where ProcureCatalogID='"+
            //    procureCatalog.ProcureCatalogID+"') Insert  Into TB_AreaProcureCataLog Select '" + 
            //    procureCatalog.ProcureCatalogID + "','" + procureCatalog.ProjectID + "','" + procureCatalog.GoodsID + "',AreaID," + 
            //    procureCatalog.ProcurePrice + " From TB_Area Where areaid%100=0 and  areaid>150000 and areaid<160000";

            string sqlcount = " select count(ProcureCatalogID) from TB_AreaProcureCataLog where ProcureCatalogID='" + procureCatalog.ProcureCatalogID + "'";
            int count = int.Parse(HZ.Data.DbHelperFactory.Create().ExecuteScalar(sqlcount).ToString());
            if (count == 0)
            {
                string sqlstr = @"  Insert  Into TB_AreaProcureCataLog Select '" + procureCatalog.ProcureCatalogID + "','" +
                    procureCatalog.ProjectID + "','" + procureCatalog.GoodsID + "',AreaID,'12.00' From TB_Area Where mod(AreaID,100)=0 and  AREAID>150000 and AREAID<160000";
                HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(sqlstr);
            }


            //return HZ.Data.DAL_Helper.OperateTable(procureCatalog, HZ.Data.TableOperator.Insert);
            Model.View_Procurecatalog_TB vpt = new View_Procurecatalog_TB();
            vpt.GoodsID = procureCatalog.GoodsID;
            vpt.ProcureCatalogID = procureCatalog.ProcureCatalogID;
            vpt.ProcurePrice = procureCatalog.ProcurePrice;
            vpt.SortSource = procureCatalog.SortSource;
            vpt.ProjectID = procureCatalog.ProjectID;
            vpt.IsUsing = procureCatalog.IsUsing;
            vpt.ProcureStartTime = DateTime.Parse("2011-1-1 10:06:09");
            vpt.ProcureEndTime = DateTime.Parse("2011-12-31 10:06:09");
            int ct = HZ.Data.DAL_Helper.OperateTableSQL<Model.View_Procurecatalog_TB>(vpt, HZ.Data.TableOperator.Insert);
            BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("插入采购目录：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            return HZ.Data.DAL_Helper.OperateTableSQL<Model.ProcureCatalog>(procureCatalog, HZ.Data.TableOperator.Insert);


        }
        /// <summary>
        /// 插入采购目录 update by zdc 系统升级后目录为View_Procurecatalog_TB
        /// </summary>
        /// <param name="procureCatalog">采购目录【采购目录编号ProcureCatalogID，商品编号GoodsID，中标价格ProcurePrice，采购项目编号ProjectID，为必填】</param>
        /// <returns></returns>
        public int AddProcureCatalog(ProcureCatalog procureCatalog, View_Procurecatalog_TB vpt)
        {
            BLL_UserSession.CheckSession();

            //生成最大编号
            string sql = "SELECT MAX(ProcureCatalogID) FROM TB_ProcureCatalog  where length(ProcureCatalogID)=8";
            object objProcureCatalogID = HZ.Data.DbHelperFactory.Create().ExecuteScalar(sql);
            if (objProcureCatalogID != null && objProcureCatalogID.ToString().Length == 8)
            {
                procureCatalog.ProcureCatalogID = (int.Parse(objProcureCatalogID.ToString()) + 1).ToString("D8");
            }
            else
            {
                procureCatalog.ProcureCatalogID = "10000001";
            }
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            // TIPS:remarked by lig 20090730
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyIDs_PS), "配送企业编号集合CompanyIDs_PS不能空");
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyNames_PS), "配送企业名称集合CompanyNames_PS不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "ProcureCatalogID不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.GoodsID), "商品编号GoodsID不能空");
            HZ.Common.ThrowHelper.Throw(procureCatalog.ProcurePrice != null, "中标价格ProcurePrice不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProjectID), "采购项目编号ProjectID不能空");
            int totalrecord = 0;
            HZ.DrugTrade.Model.Query.ProcureCatalog pc = new HZ.DrugTrade.Model.Query.ProcureCatalog()
            {
                //商品编号
                GoodsID = procureCatalog.GoodsID,
                //采购项目编号
                ProjectID = procureCatalog.ProjectID
            };
            GetProcureCatalogByWhere(pc, 1, 0, out  totalrecord);
            if (totalrecord != 0)
            {
                //2该商品在项目中已经存在（商品在同一项目中只能存在一个采购目录）
                return 2;
            }
            //添加产品也添加产品到 TB_AreaProcureCataLog  盟市 修改价格列表ProcureCatalogID, ProjectID, GoodsID, AreaID, Price
            //string sqlstr = @" if not exists(select top 1 * from TB_AreaProcureCataLog where ProcureCatalogID='"+
            //    procureCatalog.ProcureCatalogID+"') Insert  Into TB_AreaProcureCataLog Select '" + 
            //    procureCatalog.ProcureCatalogID + "','" + procureCatalog.ProjectID + "','" + procureCatalog.GoodsID + "',AreaID," + 
            //    procureCatalog.ProcurePrice + " From TB_Area Where areaid%100=0 and  areaid>150000 and areaid<160000";

            string sqlcount = " select count(ProcureCatalogID) from TB_AreaProcureCataLog where ProcureCatalogID='" + procureCatalog.ProcureCatalogID + "'";
            int count = int.Parse(HZ.Data.DbHelperFactory.Create().ExecuteScalar(sqlcount).ToString());
            if (count == 0)
            {
                string sqlstr = @"  Insert  Into TB_AreaProcureCataLog Select '" + procureCatalog.ProcureCatalogID + "','" +
                    procureCatalog.ProjectID + "','" + procureCatalog.GoodsID + "',AreaID,'12.00' From TB_Area Where mod(AreaID,100)=0 and  AREAID>150000 and AREAID<160000";
                HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(sqlstr);
            }
            vpt.ProcureCatalogID = procureCatalog.ProcureCatalogID;
            vpt.GoodsID = procureCatalog.GoodsID;
            HZ.Data.DAL_Helper.OperateTableSQL<Model.View_Procurecatalog_TB>(vpt, HZ.Data.TableOperator.Insert);
            BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("插入采购目录：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            //return HZ.Data.DAL_Helper.OperateTable(procureCatalog, HZ.Data.TableOperator.Insert);
            return HZ.Data.DAL_Helper.OperateTableSQL<Model.ProcureCatalog>(procureCatalog, HZ.Data.TableOperator.Insert);


        }

        /// <summary>
        /// 插入采购目录【为Execl批量导入用】
        /// </summary>
        /// <param name="procureCatalog">采购目录【配送企业编号集合CompanyIDs_PS，配送企业名称集合CompanyNames_PS，采购目录编号ProcureCatalogID，商品编号GoodsID，中标价格ProcurePrice，采购项目编号ProjectID，为必填】</param>
        /// <returns>0失败；1成功；2该商品在项目中已经存在（商品在同一项目中只能存在一个采购目录）</returns>
        public int AddProcureCatalogForBatch(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            // TIPS:remarked by lig 20090730
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyIDs_PS), "配送企业编号集合CompanyIDs_PS不能空");
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyNames_PS), "配送企业名称集合CompanyNames_PS不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "ProcureCatalogID不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.GoodsID), "商品编号GoodsID不能空");
            HZ.Common.ThrowHelper.Throw(procureCatalog.ProcurePrice != null, "中标价格ProcurePrice不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProjectID), "采购项目编号ProjectID不能空");

            procureCatalog.IsFlowing = false;
            procureCatalog.IsUsing = true;
            procureCatalog.AddTime = DateTime.Now;

            int totalrecord = 0;
            HZ.DrugTrade.Model.Query.ProcureCatalog pc = new HZ.DrugTrade.Model.Query.ProcureCatalog()
            {
                //商品编号
                GoodsID = procureCatalog.GoodsID,
                //采购项目编号
                ProjectID = procureCatalog.ProjectID
            };
            GetProcureCatalogByWhere(pc, 1, 0, out  totalrecord);
            if (totalrecord != 0)
            {
                //2该商品在项目中已经存在（商品在同一项目中只能存在一个采购目录）
                return 2;
            }
            BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("插入采购目录：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            return HZ.Data.DAL_Helper.OperateTable(procureCatalog, HZ.Data.TableOperator.Insert);
        }

        /// <summary>
        /// 插入采购目录（批量）
        /// </summary>
        /// <param name="procureCatalogs">采购目录集合【配送企业编号集合CompanyIDs_PS，配送企业名称集合CompanyNames_PS，采购目录编号ProcureCatalogID，商品编号GoodsID，中标价格ProcurePrice，采购项目编号ProjectID，为必填】</param>
        /// <returns></returns>
        public int AddProcureCatalogs(IList<ProcureCatalog> procureCatalogs)
        {
            BLL_UserSession.CheckSession();
            throw new NotImplementedException();
        }

        /// <summary>
        /// 更新采购目录信息（0失败;1成功）
        /// </summary>
        /// <param name="procureCatalog">采购目录</param>
        /// <returns>0失败;1成功</returns>
        public int UpdateProcureCatalog(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();
            int state = HZ.Data.DAL_Helper.OperateTable(procureCatalog, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购目录信息：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 删除一条采购目录
        /// </summary>
        /// <param name="procureCatalogID">采购目录信息【采购目录编号ProcureCatalogID必填】</param>
        /// <returns></returns>
        public int DeleteProcureCatalogByID(string procureCatalogID)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalogID), "采购目录编号不能空");
            int state = DAL.DAL_ProcureCatalog.DeleteProcureCatalogByID(procureCatalogID);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除一条采购目录：{0};处理时间:{1};)", procureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 获取采购目录信息
        /// </summary>
        /// <param name="procureCatalogID">采购目录编号【采购目录编号ProcureCatalogID必填】</param>
        /// <returns></returns>
        public HZ.DrugTrade.Model.View.ProcureCatalog GetProcureCatalogByID(string procureCatalogID)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalogID), "采购目录编号不能空");
            return DAL_ProcureCatalog.GetProcureCatalogByID(procureCatalogID);
        }

        /// <summary>
        /// 更新配送企业
        /// </summary>
        /// <param name="procureCatalog">采购目录信息【配送企业编号集合CompanyIDs_PS，配送企业名称集合CompanyNames_PS，采购目录编号ProcureCatalogID，为必填】</param>
        /// <returns></returns>
        public int UpdateProcureCatalog_CompanyPS(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            HZ.Common.ThrowHelper.Throw(procureCatalog.ProcureCatalogID != null);
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyIDs_PS), "配送企业编号集合不能空");
            //HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.CompanyNames_PS), "配送企业名称集合不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "采购目录编号ProcureCatalogID不能空");
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.CompanyIDs_PS = procureCatalog.CompanyIDs_PS;
            updatemodel.CompanyNames_PS = procureCatalog.CompanyNames_PS;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新配送企业：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 更新中标价格
        /// </summary>
        /// <param name="procureCatalog">采购目录信息【中标价ProcurePrice，采购目录编号ProcureCatalogID，为必填】</param>
        /// <param name="log">调整价格日志</param>
        /// <returns></returns>
        public int UpdateProcureCatalog_ProcurePrice(ProcureCatalog procureCatalog, Model.AdjustPriceLog log)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            HZ.Common.ThrowHelper.Throw(procureCatalog.ProcurePrice != null, "采购价ProcurePrice不能为空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "采购目录编号ProcureCatalogID不能空");
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.ProcurePrice = procureCatalog.ProcurePrice;
            int a = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            int b = HZ.Data.DAL_Helper.OperateTable(log, HZ.Data.TableOperator.Insert);
            return a & b;
        }

        /// <summary>
        /// 修改采购目录来源
        /// </summary>
        /// <param name="procureCatalog">采购目录信息【目录来源SortSource（0.正常添加；1.临时目录），采购目录编号ProcureCatalogID必填】</param>
        /// <returns></returns>
        public int UpdateProcureCatalog_SortSource(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            HZ.Common.ThrowHelper.Throw(procureCatalog.SortSource != null, "目录来源SortSource不能为空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "采购目录编号ProcureCatalogID不能空");
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.SortSource = procureCatalog.SortSource;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("修改采购目录来源：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 切换启用状态
        /// </summary>
        /// <param name="procureCatalog">采购目录信息【是否启用IsUsing（0否;1是），采购目录编号ProcureCatalogID必填】</param>
        /// <returns></returns>
        public int UpdateProcureCatalog_IsUsing(ProcureCatalog procureCatalog)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            HZ.Common.ThrowHelper.Throw(procureCatalog.IsUsing != null, "是否启用IsUsing不能为空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.ProcureCatalogID), "采购目录编号ProcureCatalogID不能空");
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.IsUsing = procureCatalog.IsUsing;

            if (updatemodel.AddTime == null)
            {
                updatemodel.AddTime = DateTime.Now;
            }
            int state = HZ.Data.DAL_Helper.OperateTableSQL<ProcureCatalog>(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("药品撤废或恢复：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 切换启用状态 升级后View_ProcureCatalog_TB add by zdc
        /// </summary>
        /// <param name="procureCatalog">采购目录信息【是否启用IsUsing（0否;1是），采购目录编号ProcureCatalogID必填】</param>
        /// <returns></returns>
        public int UpdateProcureCatalog_IsUsingZDC(View_Procurecatalog_TB procureCatalog)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(procureCatalog != null);
            HZ.Common.ThrowHelper.Throw(procureCatalog.IsUsing != null, "是否启用IsUsing不能为空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(procureCatalog.GoodsID), "采购目录编号ProcureCatalogID不能空");
            View_Procurecatalog_TB updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.IsUsing = procureCatalog.IsUsing;

            if (updatemodel.AddTime == null)
            {
                updatemodel.AddTime = DateTime.Now;
            }
            int state = HZ.Data.DAL_Helper.OperateTableSQL<View_Procurecatalog_TB>(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("药品撤废或恢复：{0};处理时间:{1};)", procureCatalog.ProcureCatalogID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        #endregion

        #region 调价+计划

        /// <summary>
        /// 立即更新价格（0失败;1成功）
        /// </summary>
        /// <param name="plan">调价计划</param>
        /// <returns>0失败;1成功</returns>
        public int UpdateProcureCatalog_Price(AdjustPricePlan plan)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PricePlanSerialID), "调价计划编号不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.ProcureCatalogID), "采购目录编号不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteStartTime != null, "开始执行不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PlanPerson), "计划制定人不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteState != null, "执行方式不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.AdjustPriceReason), "调价原因不能空");
            HZ.Common.ThrowHelper.Throw(plan.AdjustPrice != null, "待调整价格不能空");
            plan.ExecuteWay = 0;
            plan.ExecuteState = 1;
            ProcureCatalog procureCatalog = new ProcureCatalog() { ProcureCatalogID = plan.ProcureCatalogID };
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.ProcurePrice = plan.AdjustPrice;

            AdjustPriceLog log = new AdjustPriceLog()
            {
                AdjustPriceReason = plan.AdjustPriceReason,
                AdjustPricePerson = plan.PlanPerson,
                OriginalPrice = plan.OriginalPrice,
                AdjustPrice = plan.AdjustPrice,
                AdjustPriceTime = plan.ExecuteStartTime,
                PriceLogSerialID = plan.PricePlanSerialID,
                ProcureCatalogID = plan.ProcureCatalogID
            };


            //采用事务进行调价20091212
            var h = HZ.Data.DbHelperFactory.Create();
            try
            {
                h.BeginTrans();

                //string strSql = HZ.Data.DAL_Helper.GetUpdateSql(updatemodel);
                //h.ExecuteNonQuery(strSql);
                HZ.Data.DAL_Helper.UpdateModel<ProcureCatalog>(updatemodel);

                //strSql = HZ.Data.DAL_Helper.GetInsertSql(log);
                //h.ExecuteNonQuery(strSql);
                HZ.Data.DAL_Helper.InsertModel<AdjustPriceLog>(log);

                //strSql = HZ.Data.DAL_Helper.GetInsertSql(plan);
                //h.ExecuteNonQuery(strSql);
                HZ.Data.DAL_Helper.InsertModel<AdjustPricePlan>(plan);
                //系统升级后 调整相应的视图转化的物理表中的采购价格 add by zdc
                string UpdateInfo = string.Format("update View_ProcureCatalog_TB set ProcurePrice={0} where ProcureCatalogID='{1}'", plan.AdjustPrice, plan.ProcureCatalogID);
                h.ExecuteNonQuery(UpdateInfo);
                //调价更新各盟市价格
                //string strSql = string.Format(@"Update  TB_AreaProcureCataLog  Set  Price={0} Where ProcureCatalogID='{1}' and Price>{0} ", plan.AdjustPrice, plan.ProcureCatalogID);
                //调价更新各盟市价格不受价格高低约束edit by xuyi
                string strSql = string.Format(@"Update  TB_AreaProcureCataLog  Set  Price={0} Where ProcureCatalogID='{1}'", plan.AdjustPrice, plan.ProcureCatalogID);
                h.ExecuteNonQuery(strSql);
                //调价更新医疗机构价格
                //                strSql = string.Format(@"UPDATE TB_HospitalProcureCatalog
                //   SET Price = {0},SellPrice = {1} WHERE ProcureCatalogID = '{2}' and Price>{0}", plan.AdjustPrice, (plan.AdjustPrice ?? 0) * decimal.Parse("1.15"), plan.ProcureCatalogID);
                //调价更新医疗机构价格不受价格高低约束edit by xuyi
                strSql = string.Format(@"UPDATE TB_HospitalProcureCatalog
                SET Price = {0},SellPrice = {1} WHERE ProcureCatalogID = '{2}' ", plan.AdjustPrice, (plan.AdjustPrice ?? 0) * decimal.Parse("1.15"), plan.ProcureCatalogID);

                h.ExecuteNonQuery(strSql);
                //更新基础库产品列表里的中标价(即tb_goods里的BidPrice) add by zdc 20111-08-04
                strSql = string.Format(@"update tb_goods set bidprice={0} where goodsid={1}", plan.AdjustPrice, plan.ProcureCatalogID);
                h.ExecuteNonQuery(strSql);
                h.CommitTrans();
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("立即更新价格：{0};处理时间:{1};)", plan.PlanPerson, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
                return 1;
            }
            catch (Exception ee)
            {
                h.RollTrans();
                HZ.Common.log4netManager.LogDebug("UpdateProcureCatalog_Price", ee.Message, ee);
                return 0;
            }

            //int a = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            //int b = HZ.Data.DAL_Helper.OperateTable(log, HZ.Data.TableOperator.Insert);
            //int c = HZ.Data.DAL_Helper.OperateTable(plan, HZ.Data.TableOperator.Insert);

            //return a & b & c;
        }

        /// <summary>
        /// 盟市地区 立即更新价格（0失败;1成功）----盟市招标机构 修改实际采购价
        /// </summary>
        /// <param name="plan">调价计划</param>
        /// <returns>0失败;1成功</returns>
        public int UpdateAreaProcureCatalog_Price(AdjustPricePlan plan, string ProjectID, string AreaID)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PricePlanSerialID), "调价计划编号不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.ProcureCatalogID), "采购目录编号不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteStartTime != null, "开始执行不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PlanPerson), "计划制定人不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteState != null, "执行方式不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.AdjustPriceReason), "调价原因不能空");
            HZ.Common.ThrowHelper.Throw(plan.AdjustPrice != null, "待调整价格不能空");
            plan.ExecuteWay = 0;
            plan.ExecuteState = 1;
            ProcureCatalog procureCatalog = new ProcureCatalog() { ProcureCatalogID = plan.ProcureCatalogID };
            ProcureCatalog updatemodel = HZ.Data.DAL_Helper.GetModelByID(procureCatalog);
            updatemodel.ProcurePrice = plan.AdjustPrice;

            AdjustPriceLog log = new AdjustPriceLog()
            {
                AdjustPriceReason = plan.AdjustPriceReason,
                AdjustPricePerson = plan.PlanPerson,
                OriginalPrice = plan.OriginalPrice,
                AdjustPrice = plan.AdjustPrice,
                AdjustPriceTime = plan.ExecuteStartTime,
                PriceLogSerialID = plan.PricePlanSerialID,
                ProcureCatalogID = plan.ProcureCatalogID,
                AreaID = AreaID
            };


            //采用事务进行调价
            var h = HZ.Data.DbHelperFactory.Create();
            try
            {
                string strSql = "";

                h.BeginTrans();

                strSql = HZ.Data.DAL_Helper.GetInsertSql(log);

                h.ExecuteNonQuery(strSql);

                strSql = string.Format(@"UPDATE TB_AreaProcureCataLog SET Price = '" + plan.AdjustPrice + "' WHERE ProcureCatalogID = '" + plan.ProcureCatalogID + "' AND  ProjectID =  '" + ProjectID + "' AND AreaID = '" + AreaID + "' ");
                h.ExecuteNonQuery(strSql);

                strSql = string.Format(@"UPDATE TB_HospitalProcureCatalog SET Price = '{0}' WHERE ProcureCatalogID = '{1}' 
                AND HospitalID IN (SELECT HospitalID FROM TB_Hospital  WHERE AreaID IN (SELECT AreaID FROM TB_Area WHERE AreaID =  '{2}' OR FatherAreaID = '{2}'))"
                , plan.AdjustPrice, plan.ProcureCatalogID, AreaID);

                h.ExecuteNonQuery(strSql);

                h.CommitTrans();
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("盟市地区 立即更新价格：{0};处理时间:{1};)", plan.PlanPerson, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
                return 1;
            }
            catch (Exception ee)
            {
                h.RollTrans();
                HZ.Common.log4netManager.LogDebug("UpdateAreaProcureCatalog_Price", ee.Message, ee);
                return 0;
            }
        }

        ///中心查看盟市价格
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public DataTable GetAreaProductList(string ProcureCatalogID)
        {
            return DAL.DAL_ProcureCatalog.GetAreaProductList(ProcureCatalogID);
        }

        /// <summary>
        /// 盟市价格权限
        /// </summary>
        /// <param name="strUserID"></param>
        /// <returns></returns>
        public DataTable GetAreaAccessPrice()
        {
            return DAL.DAL_ProcureCatalog.GetAreaAccessPrice();
        }

        /// <summary>
        /// 保存盟市价格权限
        /// </summary>
        /// <param name="hospitalprocurecatalogList"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public int ValidateAreaAccessPrice(List<ManageOrg> moList)
        {
            BLL_UserSession.CheckSession();

            int isOK = 0;
            var sh = HZ.Data.DbHelperFactory.Create();
            try
            {
                sh.BeginTrans();

                foreach (var item in moList)
                {
                    //string sql = HZ.Data.DAL_Helper.GetUpdateSql(item);
                    //sh.ExecuteNonQuery(sql);
                    HZ.Data.DAL_Helper.OperateTableSQL<Model.ManageOrg>(item, HZ.Data.TableOperator.Update);
                }
                sh.CommitTrans();
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("保存盟市价格权限;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
                isOK = 1;
            }
            catch (Exception ee)
            {
                HZ.Common.log4netManager.LogDebug("DAL_ProcureCatalog", ee.Message, ee);
                sh.RollTrans();
#if DEBUG
                throw ee;
#endif
            }

            return isOK;
        }

        /// <summary>
        /// 新增调价计划（0失败;1成功）
        /// </summary>
        /// <param name="plan">调价计划</param>
        /// <returns>0失败;1成功</returns>
        public int AddAdjustPricePlan(AdjustPricePlan plan)
        {

            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PricePlanSerialID), "调价计划编号不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.ProcureCatalogID), "采购目录编号不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteStartTime != null, "开始执行不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PlanPerson), "计划制定人不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteState != null, "执行方式不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.AdjustPriceReason), "调价原因不能空");
            HZ.Common.ThrowHelper.Throw(plan.AdjustPrice != null, "待调整价格不能空");
            plan.ExecuteWay = 1;
            plan.ExecuteState = 0;
            int state = HZ.Data.DAL_Helper.OperateTableSQL(plan, HZ.Data.TableOperator.Insert, HZ.Data.DbHelperFactory.Create());
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("新增调价计划：{0};处理时间:{1};)", plan.PlanPerson, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 更新调价计划（0.不成功,1.成功,2.调价计划编号不存在）
        /// </summary>
        /// <param name="plan">调价计划</param>
        /// <returns>0失败;1成功</returns>
        public int UpdateAdjustPricePlan(AdjustPricePlan plan)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PricePlanSerialID), "调价计划编号不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.ProcureCatalogID), "采购目录编号不能空");
            HZ.Common.ThrowHelper.Throw(plan.ExecuteStartTime != null, "开始执行不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.PlanPerson), "计划制定人不能空");
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(plan.AdjustPriceReason), "调价原因不能空");
            HZ.Common.ThrowHelper.Throw(plan.AdjustPrice != null, "待调整价格不能空");
            HZ.Common.ThrowHelper.Throw(plan.OriginalPrice != null, "原价格不能空");

            plan.ExecuteState = 0;
            plan.ExecuteWay = 1;
            int state = HZ.Data.DAL_Helper.OperateTableSQL(plan, HZ.Data.TableOperator.Update, HZ.Data.DbHelperFactory.Create());
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新调价计划：{0};处理时间:{1};)", plan.PlanPerson, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 删除调价计划（0.不成功,1.成功,2.调价计划编号不存在）
        /// </summary>
        /// <param name="planID">调价计划编号</param>
        /// <returns>0失败;1成功</returns>
        public int DeleteAdjustPricePlanByID(string planID)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(planID), "调价计划编号不能空");
            AdjustPricePlan plan = new AdjustPricePlan() { PricePlanSerialID = planID };
            int state = HZ.Data.DAL_Helper.OperateTableSQL(plan, HZ.Data.TableOperator.Delete, HZ.Data.DbHelperFactory.Create());
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除调价计划：{0};处理时间:{1};)", planID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
            // return DAL.DAL_ProcureCatalog.DeleteAdjustPricePlanByID(planID);
        }


        /// <summary>
        /// 条件查询调价计划信息
        /// </summary>
        /// <param name="plan">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public IList<HZ.DrugTrade.Model.View.AdjustPricePlan> GetAdjustPricePlanByWhere(HZ.DrugTrade.Model.Query.AdjustPricePlan plan, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //plan.ExecuteWay = 1;去除只显示定时执行，改成全部adit by xy20121221
            return DAL.DAL_ProcureCatalog.GetAdjustPricePlanByWhere(plan, currentpage, pagesize, out totalrecord);
        }
        /// <summary>
        /// 条件查询调价计划信息表 add by zdc 2011-10-21
        /// </summary>
        /// <param name="plan">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public System.Data.DataTable GetAdjustPricePlanDTByWhere(HZ.DrugTrade.Model.Query.AdjustPricePlan plan, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            plan.ExecuteWay = 1;
            return DAL.DAL_ProcureCatalog.GetAdjustPricePlanDTByWhere(plan, currentpage, pagesize, out totalrecord);
        }
        /// <summary>
        /// 执行调价计划
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public int ExecuteAdjustPrice(Model.AdjustPricePlan plan)
        {
            HZ.Common.ThrowHelper.Throw(plan.ProcureCatalogID != null);
            HZ.Common.ThrowHelper.Throw(plan.ExecuteState != null);
            int state = DAL.DAL_AdjustPricePlan.ExecuteAdjustPrice(plan);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("执行调价计划：{0};处理时间:{1};)", plan.PlanPerson, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;

        }

        /// <summary>
        /// 获取调价记录 zdc
        /// </summary>
        /// <param name="procurecatalogId">采购目录编号</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示数</param>
        /// <param name="totalRecord">总数</param>
        /// <returns></returns>
        public IList<Model.AdjustPricePlan> GetAdjustPricePlanByWhere(string procurecatalogId, int currentPage, int pageSize, out int totalRecord)
        {
            return DAL_ProcureCatalog.GetAdjustPricePlanByWhere(procurecatalogId, currentPage, pageSize, out totalRecord);
        }

        /// <summary>
        /// 获取一条调价目录 zdc
        /// </summary>
        /// <param name="procureCatalogID">采购目录编号</param>
        /// <returns></returns>
        public HZ.DrugTrade.Model.AdjustPricePlan GetAdjustPricePlanByID(string procureCatalogID)
        {
            return DAL_ProcureCatalog.GetAdjustPricePlanByID(procureCatalogID);
        }
        #endregion

        /// <summary>
        /// 根据机构ID判断是否基层医疗机构 add by zdc
        /// </summary>
        /// <param name="orgID"></param>
        /// <returns></returns>
        public bool GetIsJiCeng(string orgID)
        {
            return DAL_ProcureCatalog.GetIsJiCeng(orgID);
        }

        #endregion

        /// <summary>
        /// 提交/审核产品信息 modfiy by ysm 2013-01-29
        /// </summary>
        /// <param name="GoodsId">产品编号</param>
        /// <param name="flag">0 提交 1 审核通过 2 审核不通过</param>
        /// <param name="NoPassReson">不通过原因</param>
        /// <returns></returns>
        public int SubmitProcureCatalogList(string GoodsId, int flag, string NoPassReson)
        {
            BLL_UserSession.CheckSession();
            BLL_Log log = new BLL_Log();

            int result = DAL_ProcureCatalog.SubmitProcureCatalogList(GoodsId, flag, NoPassReson, BLL_UserSession.GetCurrentUser().UserName);
            if (flag == 0) //提交
            {
                if (result > 0)
                {
                    string Messg = string.Format("产品{0}提交成功！", GoodsId);
                    log.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = Messg, ClientIP = HZ.Fun.GetClientIP() });
                }
            }
            if (flag == 1) //审核通过
            {
                if (result > 0)
                {
                    string Messg = string.Format("产品{0}审核通过！", GoodsId);
                    log.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = Messg, ClientIP = HZ.Fun.GetClientIP() });
                }
            }
            if (flag == 2) //审核不通过
            {
                if (result > 0)
                {
                    string Messg = string.Format("产品{0}审核不通过！", GoodsId);
                    log.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = Messg, ClientIP = HZ.Fun.GetClientIP() });
                }
            }
            return result;
        }

        public int UpdateProcureCatalogList(Model.View.ProcureCatalog list)
        {
            int flag = 0;
            BLL_UserSession.CheckSession();
            flag = DAL_ProcureCatalog.UpdateProcureCatalogList(list);
            BLL_Log log = new BLL_Log();
            if (flag == 1)
            {
                string Messg = string.Format("成功修改产品{0}内容：包装单位修改为【{1}】,最小零售数量修改为【{2}】", list.GoodsID, list.PackUnit, list.PackCount);
                log.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = Messg, ClientIP = HZ.Fun.GetClientIP() });
            }
            return flag;
        }
          /// <summary>
        /// 条件查询采购目录信息（有效的【在采购项目有效期内】）医疗机构
        /// add by Meng 2013-04-22 添加医疗机构设置的实际采购价格
        /// </summary>
        /// <param name="procureCatalog">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns>所有采购目录信息</returns>
        public IList<Model.View.ProcureCatalog> GetProcureCatalogByWhere_Hospital(HZ.DrugTrade.Model.Query.ProcureCatalog procurecatalog, string hospitalid, int currentPage, int pageSize, out int totalRecord)
        {
            BLL_UserSession.CheckSession();
            return DAL_ProcureCatalog.GetProcureCatalogByWhere_Hospital(procurecatalog, hospitalid, currentPage, pageSize, out totalRecord);
        }
    }
}
